class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> map;
        int left = 0;
        int right = 0;
        int count = INT_MIN;
        while (right < s.size())
        {
            map[s[right]]++;
            while (map[s[right]] == 2)
            {
                map[s[left]]--;
                left++;
            }
            count = max(count, right - left + 1);
            right++;
        }
        return count == INT_MIN ? 0 : count;
    }
};